using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 闪现技能，实质上是速度非常快的移动，闪现过程中角色还会存在于地图中，并不会短暂消失
/// 如果是改变角色位置的那种闪现，由于不是以角色为中心，所以效果会很鬼畜，故不采用
/// </summary>
public class FlashMoveSkill : abstuctSkill
{
    /// <summary>
    /// 闪现距离
    /// </summary>
    public float distance;
    /// <summary>
    /// 闪现速度
    /// </summary>
    public float velocity;
    private Vector3 initPosition;

    protected override void onExecute()
    {
        //throw new System.NotImplementedException();
        this.gameObject.SetActive(true);
        initPosition = new Vector3(source.transform.position.x, source.transform.position.y);

        playerControl player = source.GetComponent<playerControl>();

        if (source.transform.localScale.x > 0)
        {
            if (Input.GetKey(player.right) && Input.GetKey(player.up))
            {
                source.GetComponent<playerControl>().move(new Vector3(velocity, velocity, 0));

            }
            else if (!Input.GetKey(player.right) && Input.GetKey(player.up))
            {
                source.GetComponent<playerControl>().move(new Vector3(0, velocity, 0));

            }
            else if (Input.GetKey(player.right) && Input.GetKey(player.down))
            {
                source.GetComponent<playerControl>().move(new Vector3(velocity, -velocity, 0));

            }
            else if (!Input.GetKey(player.right) && Input.GetKey(player.down))
            {
                source.GetComponent<playerControl>().move(new Vector3(0, -velocity, 0));

            }

            else
            {
                source.GetComponent<playerControl>().move(new Vector3(velocity, 0, 0));

            }

        }
        else
        {
            if (Input.GetKey(player.left) && Input.GetKey(player.up))
            {
                source.GetComponent<playerControl>().move(new Vector3(-velocity, velocity, 0));

            }
            else if (!Input.GetKey(player.left) && Input.GetKey(player.up))
            {
                source.GetComponent<playerControl>().move(new Vector3(0, velocity, 0));

            }
            else if (Input.GetKey(player.left) && Input.GetKey(player.down))
            {
                source.GetComponent<playerControl>().move(new Vector3(-velocity, -velocity, 0));

            }
            else if (!Input.GetKey(player.left) && Input.GetKey(player.down))
            {
                source.GetComponent<playerControl>().move(new Vector3(0, -velocity, 0));

            }

            else
            {
                source.GetComponent<playerControl>().move(new Vector3(-velocity, 0, 0));

            }

        }

    }
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Vector3.Distance(initPosition, source.transform.position) > distance)
        {
            source.GetComponent<playerControl>()._velocity.x = 0;
            source.GetComponent<playerControl>()._velocity.y = 0;
            Destroy(gameObject);

        }
    }
}
